<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

class RedisController extends Controller
{
    //------------------------------字符串操作-------------------
    public function stringGet($key){
        $value = Redis::get($key);
        dump($value);
    }

    public function stringSet($key,$value){
        Redis::set($key,$value);
    }
    //----------------------------计数器操作-----------------------
    public function incr($key){
        //每次执行会自增
        Redis::incr($key);
    }
    //------------------------------列表(可以实现堆栈后入先出和队列先入先出)-------------------------
    public function listGetAll($listname){
        $value = Redis::lrange($listname,0,-1);
        dump($value);
    }
    //队列
    public function queueSet($listname,$value){
        //从左侧入
        Redis::lpush($listname,$value);
    }
    
    public function queueGet($listname){
        //从右侧出，弹出并删除
        $value = Redis::rpop($listname);
        dump($value);
    }
    //堆栈
    public function stackSet($listname,$value){
        //从右侧入
        Redis::rpush($listname,$value);
    }
    public function stackGet($listname){
        //从右侧出，弹出并删除
        $value = Redis::rpop($listname);
        dump($value);
    }
    //---------------集合（一组 不重复 的 无序 元素）------------------------------
    public function setSets($setsname,$value){
        Redis::sadd($setsname,$value);
    }
    public function getSets($setsname){
        $value = Redis::smembers($setsname);
        dump($value);
    }
    //--------------有序集合（一组 不重复 的 排序 元素）---------------------------
    //设置
    public function setSortedSets($setsname,$index=0,$value){
        Redis::zadd($setsname,$index,$value);
    }
    //正序查看
    public function getSortedSets($setsname){
        $value = Redis::zrange($setsname,0,-1);
        dump($value);
    }
    //倒叙查看
    public function getReverseSortedSets($setsname){
        $value = Redis::zrevrange($setsname,0,-1);
        dump($value);
    }
    //提升有序集合一名成员在排序中的评分(步进)
    public function upSortedSetsMember($setname,$value){
        Redis::zincrby($setname,1,$value);
    }
    //----------------哈希字典(map)------------------------------
    //单次设置一个
    public function setHash($hash,$key,$value){
        Redis::hset($hash,$key,$value);
    }
    //单次设置多个
    // public function setMulHash(){

    // }
    public function getHash($hash,$key){
        $value = Redis::hget($hash,$key);
        dump($value);
    }
}
